package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
    //套餐分页查询
    Page<SetmealVO> list(SetmealPageQueryDTO dto);
    //新增套餐
    @AutoFill(OperationType.INSERT)
    void add(Setmeal setmeal);
    //根据id查询套餐
    @Select("select *from setmeal s left join setmeal_dish d on s.category_id=d.id where s.id=#{id}")
    SetmealVO getSetmealById(Long id);
    //根据id查setmeal_dish
    @Select("select *from setmeal_dish where setmeal_id=#{id}")
    List<SetmealDish> getSetmealDishBuId(Long id);
    //更新套套餐基本信息
    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);
    //批量删除套餐
    void deleteById(List<Long> ids);
    //修改套餐状态
    @Update("update setmeal set status=#{status} where id=#{id}")
    void updateSetmealStatus(Integer status, Long id);
    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> newList(Setmeal setmeal);
    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
